﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.SharePoint;

namespace Eneta.Portal.Companies.Controls
{
    public class CompanySearchControl : UserControl
    {
        protected Repeater companiesList;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            companiesList.ItemDataBound += new RepeaterItemEventHandler(companiesList_ItemDataBound);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var web = SPContext.Current.Site.OpenWeb("/firmad/");
            var list = web.Lists["Lehed"];

            var queryString = "<Where><FieldRef Name='ContentType'/><Value Type='Text'>Firma</Value></Where>";
            queryString += "<OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";

            var query = new SPQuery();
            query.Query = queryString;
            query.RowLimit = 6;

            var items = list.GetItems(query);

            companiesList.DataSource = items;
            companiesList.DataBind();
        }

        protected void companiesList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

        }
    }
}
